package com.example.service.aboutSchools.impl;

import com.example.pojo.aboutSchool.Schools;
import com.example.service.aboutSchools.SchoolService;

import java.util.ArrayList;
import java.util.List;

public class SchoolServiceImpl implements SchoolService {
    private List<Schools> schools = new ArrayList<>();

    @Override
    public void addSchool(Schools school) {
        schools.add(school);
    }

    @Override
    public void updateSchool(Schools school) {
        for (Schools s : schools) {
            if (s.getId() == school.getId()) {
                s.setSchoolName(school.getSchoolName());
                s.setSchoolType(school.getSchoolType());
                s.setSchoolLogo(school.getSchoolLogo());
                s.setSchoolMajorId(school.getSchoolMajorId());
                break;
            }
        }
    }

    @Override
    public void deleteSchool(int id) {
        schools.removeIf(s -> s.getId() == id);
    }

    @Override
    public Schools getSchoolById(int id) {
        for (Schools s : schools) {
            if (s.getId() == id) {
                return s;
            }
        }
        return null;
    }

    @Override
    public List<Schools> getAllSchools() {
        return schools;
    }
}
